/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-07-25
 * Time: 21:32
 */
class Solution16 {
    public String optimalDivision(int[] nums) {
        int n = nums.length;
        StringBuilder ret = new StringBuilder();

        if(n == 1) {
            return ret.append(nums[0]).toString();
        }

        if(n == 2) {
            return ret.append(nums[0]).append("/").append(nums[1]).toString();
        }

        ret  = ret.append(nums[0]).append("/(").append(nums[1]);

        for(int i = 2; i < n;i++) {
            ret.append("/").append(nums[i]);
        }
        ret.append(")");

        return ret.toString();
    }
}
